package com.osfw.dbadminer.service.jdbc;

import lombok.extern.slf4j.Slf4j;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

@Slf4j
public class JdbcAsyncFactory {

    public void executeAsyncTask(JdbcAsyncCallBack callBack, String task, Connection connect, Statement statement, ResultSet resultSet){
        log.info(callBack.getClass() + "异步任务--》" + task);
        try {
            if(connect != null && statement != null && resultSet != null){
                resultSet.close();
                statement.close();
                connect.close();
            }else if(connect != null && statement != null && resultSet == null){
                statement.close();
                connect.close();
            }else if(connect != null && statement == null && resultSet == null){
                connect.close();
            }
            callBack.solve(callBack.getClass() + "异步任务--》" + task + "完成", null);
        }catch (SQLException e){
            log.error("异常任务", e);
            callBack.solve(callBack.getClass() + "异步任务--》" + task + "异常", connect);
        }
    }

}
